#ifndef __IIC_MULTI_TOUCH_H__
#define __IIC_MULTI_TOUCH_H__

#include <linux/i2c.h>

#include "iic.h"

#define DEV_CNT                 1
#define CHRDEV_NAME             "multitouch"

#define TOUCH_HORIZENT_PIX      480
#define TOUCH_VERTICAL_PIX      272

#define MAX_SUPPORT_POINTS      5       /* 5点触摸 */
#define TOUCH_EVENT_DOWN        0x00    /* 按下 */
#define TOUCH_EVENT_UP          0x01    /* 抬起 */
#define TOUCH_EVENT_ON          0x02    /* 接触 */
#define TOUCH_EVENT_RESERVED    0x03    /* 保留 */

/* 寄存器 */
#define GT_CTRL_REG             0x8040  /* 控制命令 */
#define GT_MOD_SW_REG           0x804D  /* 模式切换命令 */
#define GT_9xx_CFGS_REG         0x8047  /* gt9xx配置 */
#define GT_1xx_CFGS_REG         0x8050  /* gt1xx配置 */
#define GT_CHECK_REG            0x80FF  /*  */
#define GT_PID_H_REG            0x8140  /* PID高字节 */
#define GT_PID_L_REG            0x8141  /* PID低字节 */

#define GT_STATUS_REG           0x814E    /* 触摸状态寄存器 */
#define GT_TP_OFFSET            8
#define GT_TP1_REG              0x814F    /* 触摸点1起始寄存器 */
#define GT_TP2_REG              0x8157    /* 触摸点2起始寄存器 */
#define GT_TP3_REG              0x815F    /* 触摸点3起始寄存器 */
#define GT_TP4_REG              0x8167    /* 触摸点4起始寄存器 */
#define GT_TP5_REG              0x816F    /* 触摸点5起始寄存器 */
#define GT_TP6_REG              0x8177    /* 触摸点6起始寄存器 */
#define GT_TP7_REG              0x817F    /* 触摸点7起始寄存器 */
#define GT_TP8_REG              0x8187    /* 触摸点8起始寄存器 */
#define GT_TP9_REG              0x818F    /* 触摸点9起始寄存器 */
#define GT_TP10_REG             0x8197    /* 触摸点10起始寄存器 */

#define GT_READ_LEN             29      /* 要读取的寄存器个数 */
#if 0
#define GT_IRQ_MODE_REG         0xA4    /* 中断模式 */
#endif

struct iic_dev gt1151dev;

static int gt1151_open(struct inode *inode, struct file *filp);
static ssize_t gt1151_write(struct file *filp, char __user *buf, size_t cnt, loff_t *offt);
static int gt1151_release(struct inode *inode, struct file *filp);

static int gt1151_probe(struct i2c_client *client, const struct i2c_device_id *id);
static int gt1151_remove(struct platform_device *dev);

static int gt1151_read_reg(struct iic_dev *gt1151dev, u16 reg, u8 *data);
static int gt1151_write_reg(struct iic_dev *gt1151dev, u16 reg, u8 data);
static int gt1151_read_coordination(struct iic_dev *gt1151dev, u16 reg, u8 *point);
static int gt1151_reset(struct i2c_client *client, struct iic_dev *gt1151dev);
static int gt1151_irq(struct i2c_client *client, struct iic_dev *gt1151dev);
static irqreturn_t touch_handler(int irq, void *dev_id);
static int gt1151_init(struct i2c_client *client, struct iic_dev *gt1151dev);
static int gt1151_input_register(struct i2c_client *client, struct iic_dev *gt1151dev);

/* 总线设备注册 */
const struct i2c_device_id iic_device_id[] = {
    {"goodix,gt1151", 0},
    {}
};

const struct of_device_id iic_of_match[] = {
    { .compatible = "goodix,gt1151" },
    { /* Sentinel */ }
};

static struct i2c_driver gt1151_driver = {
    .probe = gt1151_probe,
    .remove = gt1151_remove,
    .driver = {
        .owner = THIS_MODULE,
        .name = "gt1151_i2c",
        .of_match_table = iic_of_match,
    },
    .id_table = iic_device_id,
};

#endif
